package com.xwtec.proxy.v4;

import java.util.Random;

/**
 * @Author: zt
 * @Date: 2021/3/2 22:01
 *
 * 利用聚合，使用组合代理就比较困难（比如说先记录时间后记录日志，或者先记录日志 后记录时间）
 */
public class Tank implements Movable {
    @Override
    public void move() {

        System.out.println("Tank Move claclacla.....");
        try {
            Thread.sleep(new Random().nextInt(4000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}

interface Movable{
    void move();
}

//时间代理
class TankTimeProxy implements Movable {
    Tank m ;

    public TankTimeProxy(Tank m) {
        this.m = m;
    }

    @Override
    public void move() {
        long start  = System.currentTimeMillis();
        m.move();
        long end = System.currentTimeMillis();
        System.out.println(end-start);

    }


}
//日志代理
class TankLogProxy implements Movable {
    Tank m ;

    public TankLogProxy(Tank m) {
        this.m = m;
    }

    @Override
    public void move() {
        System.out.println("Tank start moving");
        m.move();
        System.out.println("Tank end moving");

    }




}